package day_2022_1_to_2.leetcode;

import java.util.Arrays;

public class Num290 {
    public static void main(String[] args) {
        String pattern="abba";
        String s="dog hh hh dog";
        System.out.println(wordPattern(pattern,s));
    }
    public static boolean wordPattern(String pattern, String s) {
        String[] data=pattern.split("");
        String[] data2=s.split(" ");
        int[] arr=new int[data.length];
        int[] arr2=new int[data2.length];
        int a=0;
        int b=0;
        if(data.length!=data2.length){
            return false;
        }
        for (int i = 0; i < data.length; i++) {
            for (int j = 0; j < data.length; j++) {
                if(data[i].equals(data[j])){
                    arr[i]=a;
                }
                if(data2[i].equals(data2[j])){
                    arr2[i]=b;
                }
                a++;
                b++;
            }
        }
        if((Arrays.toString(arr)).equals(Arrays.toString(arr2))){
            return true;
        }else {
            return false;
        }
    }
}

